package com.shop.controller;

import org.apache.http.client.methods.HttpHead;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class ResetTempMqController {
    @Autowired
    private RestTemplate restTemplate;
    @Value("${server.port}")
    private String port;

    //刷新config
    @PostMapping("/myRefresh")
    public ResponseEntity<String> myTemp() {

        //1.设置请求头
        //2.组装url
        //3.发请求
        String url = "http://localhost:" + port + "/actuator/bus-refresh";
        HttpHeaders httpHeaders = new HttpHeaders();   //请求头
        httpHeaders.add("content-type", "application/json:charset=utf-8");
        //设置进httpentry
        HttpEntity stringHttpEntity = new HttpEntity<String>(httpHeaders);
        ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, stringHttpEntity, String.class);
        //成功与失败
        if (responseEntity.getStatusCode().equals(HttpStatus.NO_CONTENT)) {
            return  ResponseEntity.ok("刷新配置成功");
        } else {
            return ResponseEntity.badRequest().body("刷新配置失败");
        }

    }


}
